package mylist;

import java.util.*;

/**
 * @Author 12629
 * 类的使用者
 * @Description：
 */
public class Test {


    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        //1. 先处理第一行
        List<Integer> list = new ArrayList<>();
        list.add(1);
        ret.add(list);
        //2. 从第2行开始计算 每个list当中的数据
        for(int i = 1;i < numRows;i++) {
            //3. 先准备当前行数据
            List<Integer> curRow =  new ArrayList<>();
            //4. 准备当前行的第一个数据
            curRow.add(1);
            // 5. 准备当前的中间数据
            List<Integer> prevRow = ret.get(i-1);
            for(int j = 1; j < i;j++) {
                int val = prevRow.get(j) + prevRow.get(j-1);
                curRow.add(val);
            }
            //6. 准备当前行最后一个数据
            curRow.add(1);
            //7. 把这个数据放到二维数组当中去
            ret.add(curRow);
        }
        return ret;
    }




    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<>();

        List<Integer> list2 = new ArrayList<>();


        List<List<Integer>> list3 = new ArrayList<>();
        list3.add(new ArrayList<>());

        list3.add(new ArrayList<>());



        System.out.println("=====");
    }


    public static void main22(String[] args) {
        Collection<Integer> collection = new ArrayList<>();
        Collection<Integer> collection2 = new LinkedList<>();
        Collection<Integer> collection3 = new TreeSet<>();


        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        System.out.println(list);

        for(Integer x : list) {
            System.out.print(x+" ");
        }
        System.out.println();

        //使用 迭代器 遍历集合类 list
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next()+" ");
        }

       /* //并不会产生新的对象！
        List<Integer> list1 = list.subList(1,3);

        System.out.println(list1);
        System.out.println("==============");

        list1.set(0,99);
        System.out.println(list1);
        System.out.println(list);
*/


        /*ArrayList<Number> list123 = new ArrayList<>();
        list123.addAll(list);
        System.out.println(list123);//123

        list123.remove(new Integer(2));
        System.out.println(list123);//23

        list123.get(0);
        list123.set(1,2);
        list123.contains(1);*/
    }


    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        for(int i = 0;i < list.size();i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();

        ArrayList<Number> list12 = new ArrayList<>(list);


        LinkedList<Integer> list1 = new LinkedList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);

        ArrayList<Number> list123 = new ArrayList<>(list1);
        list123.add(99);
        list123.add(88);

        System.out.println(list123);




        /*System.out.println(list);

        ArrayList<Integer> list2 = new ArrayList<>(15);


        list.clear();

        list2.clear();*/


    }



    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);//0
        myArrayList.add(2);//1
        myArrayList.add(199);//2
        myArrayList.display();

        //myArrayList.set(2,88888);

        //myArrayList.display();

        myArrayList.remove(199);
        myArrayList.display();

        myArrayList.clear();
        System.out.println("====");
        myArrayList.display();

    }
}
